package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.model.product.SpuInfo;
import com.atguigu.gmall.product.service.BaseTradeMarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTradeMarkController {
    @Autowired
    private BaseTradeMarkService baseTradeMarkService;
    // /admin/product/baseTrademark/{page}/{limit}

    /**
     * 品牌分页
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("{page}/{limit}")
    public Result getTrademarkPage(@PathVariable Long page,
                                 @PathVariable Long limit){
        IPage iPage=new Page(page,limit);
        IPage trademarkPage=baseTradeMarkService.getTrademarkPage(iPage);
        return Result.ok(trademarkPage);
    }

    /**
     *  删除
     * @param id
     * @return
     */
    // /admin/product/baseTrademark/remove/{id}
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Long id){
        baseTradeMarkService.removeById(id);
        return  Result.ok();
    }

    /**
     * 保存
     * @param baseTrademark
     * @return
     */
    // /admin/product/baseTrademark/save
    @PostMapping("save")
    public Result save(@RequestBody BaseTrademark baseTrademark){
        baseTradeMarkService.save(baseTrademark);
        return  Result.ok();
    }
    // /admin/product/baseTrademark/update
    @PutMapping("update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
        baseTradeMarkService.updateById(baseTrademark);
        return Result.ok();
    }

    /**
     * 回显数据
     * @param id
     * @return
     */
    // /admin/product/baseTrademark/get/{id}
    @GetMapping("/get/{id}")
    public Result getById(@PathVariable Long id){
        BaseTrademark baseTrademark =baseTradeMarkService.getById(id);
        return Result.ok(baseTrademark);
    }
}
